package com.cloud.fileservice.controller;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.cloud.fileservice.feign.AiService;

@RestController
@RefreshScope
public class TestController {
	@Value("${es.host:localhost}")
	private String esHost;
	@Autowired
	private AiService aiService;
	
	@RequestMapping("/")
	public String index() {
		return "Here is File Service!";
	}
	
	
	@RequestMapping("/getFileList")
	public String getFileList() {
		File fs=new File("/home/moon/图片/");
		if(fs!=null&&fs.isDirectory()) {
			File[] files=fs.listFiles();
			List<File> fileLs=Arrays.asList(files);
			String filenames=fileLs.stream().filter(f->f.getName().contains("png")).map(f->f.getName()).collect(Collectors.joining(", "));
			
		return filenames;
		}else {
			return "There is not File!";
		}
	}
	
	@RequestMapping("/ga")
	public String ga() {
		return aiService.getAiService();
	}
	
	@RequestMapping("/gv")
	public String gv() {
		return esHost;
	}
	
    @GetMapping(value = "/hello")
    @SentinelResource("hello")
    public String hello() {
    	var s=aiService.getAiService();
    	System.out.println(s); 
        return s;
    }
}
